import {
  reqGetBannerListData,
  reqGetBaseCategoryList,
  reqGetFloorsListData,
} from "@/api";

const state = {
  // 三级导航数据
  categoryList: [],

  // 轮播图数据
  bannerList: [],

  // 楼层数据
  floorsList: [],
};
const actions = {
  // 1. 获取三级导航数据
  async getCategoryList({ commit }) {
    const result = await reqGetBaseCategoryList();
    if (result.code === 200) {
      commit("SAVE_CATEGORY_LIST", result);
    } else {
      console.log(result.message);
    }
  },
  // 2. 获取轮播图数据
  async getBannerListData({ commit }) {
    const result = await reqGetBannerListData();
    if (result.code === 200) {
      // data:{code:200,msg,data}
      commit("SAVE_BANNER_LIST_DATA", result.data);
    } else {
      console.log(result.message);
    }
  },
  // 3. 获取楼层数据
  async getFloorsListData({ commit }) {
    const result = await reqGetFloorsListData();
    // 判断请求是否成功
    if (result.code === 200) {
      commit("SAVE_FLOORS_LIST_DATA", result.data);
    } else {
      console.log(result.message);
    }
  },
};
const mutations = {
  // 1. 保存三级导航数据
  SAVE_CATEGORY_LIST(state, payload) {
    state.categoryList = payload.data;
  },
  // 2. 存储轮播图数据
  SAVE_BANNER_LIST_DATA(state, bannerList) {
    state.bannerList = bannerList;
  },
  // 3. 存储楼层数据
  SAVE_FLOORS_LIST_DATA(state, floorsList) {
    state.floorsList = floorsList;
  },
};
const getters = {};

export default {
  namespaced: true, // 设置命名空间 用来区分不同的模块
  state,
  actions,
  mutations,
  getters,
};
